package cz.mtq.mgsc;

import java.io.IOException;

import javax.microedition.lcdui.Font;

import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;

/**
 * 
 * <a href="http://minigolfscorecard.googlecode.com/">MiniGolf Scorecard</a>
 * 
 * @author Miroslav Tichý
 *
 */
public final class Settings {

	public static final int MAX_NAME_LENGTH = 6;

	private static int NAME_CELL_WIDTH;
	private static int HOLE_CELL_WIDTH;
	private static int CELL_HEIGHT;
	private static int ONE_DIGIT_MARGIN;
	private static int TWO_DIGIT_MARGIN;
	private static int CHAR_WIDTH;

	public static final String TEXT_APP_NAME = "app_name";
	public static final String TEXT_PLAY = "play";
	public static final String TEXT_MANUAL_MOVE_MODE = "man_move_mode";
	public static final String TEXT_AUTO_MOVE_MODE = "auto_move_mode";
	public static final String TEXT_EXIT = "exit";
	public static final String TEXT_NUMBER_OF_PLAYERS = "num_of_players";
	public static final String TEXT_PLAYERS_NAME = "player_name";
	public static final String TEXT_MANUAL_MOVE_WITH_INCREMENT_MODE = "man_move_mode_with_incr";
	public static final String TEXT_MODE = "mode";
	public static final String TEXT_LANGUAGE = "lang";
	public static final String TEXT_MAIN_MODE = "standard_mode";
	public static final String TEXT_END_OF_THE_GAME_MODE = "end_of_game_mode";
	public static final String TEXT_YES = "yes";
	public static final String TEXT_NO = "no";
	public static final String TEXT_EXIT_CONFIRM = "exit_confirm";

	/**
	 * 
	 * @param midlet
	 * @return locale
	 *         TODO implement reading default locale from record store
	 */
	public static String getDefaultLocale(MgscMidlet midlet) {
		return "cs";
	}

	public static void setResoureBundleLocale(String locale) {
		try {
			UIManager.getInstance().setResourceBundle(Resources.open("/messages.res").getL10N("messages", locale));
		} catch (IOException e) {
			throw new RuntimeException(e.getMessage());
		}
	}

	public static String getResource(String key) {
		return (String) UIManager.getInstance().getResourceBundle().get(key);
	}

	/**
	 * Initialize cells (name and hole cell) width and height
	 * 
	 * @param font
	 */
	public static void initCellSize(Font font) {
		CHAR_WIDTH = font.stringWidth("X");
		NAME_CELL_WIDTH = MAX_NAME_LENGTH * CHAR_WIDTH;
		HOLE_CELL_WIDTH = 2 * CHAR_WIDTH + CHAR_WIDTH / 2;
		TWO_DIGIT_MARGIN = CHAR_WIDTH / 4;
		ONE_DIGIT_MARGIN = 3 * CHAR_WIDTH / 4;// TWO_DIGIT_MARGIN + CHAR_WIDTH / 2;
		CELL_HEIGHT = font.getHeight();
	}

	private Settings() {
	}

	public static int getNAME_CELL_WIDTH() {
		return NAME_CELL_WIDTH;
	}

	public static int getHOLE_CELL_WIDTH() {
		return HOLE_CELL_WIDTH;
	}

	public static int getCELL_HEIGHT() {
		return CELL_HEIGHT;
	}

	public static int getONE_DIGIT_MARGIN() {
		return ONE_DIGIT_MARGIN;
	}

	public static int getCHAR_WIDTH() {
		return CHAR_WIDTH;
	}

	public static int getTWO_DIGIT_MARGIN() {
		return TWO_DIGIT_MARGIN;
	};

}
